#-------------------------------------------------------------------------------
# Name:        Payload
# Purpose:      Lay du lieu tu file cau hinh xml
#
# Author:      Mr.Junz-N
#
# Created:     12/12/2012
# Copyright:   (c) Mr.Junz-N 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------
import xml.dom.minidom
from xml.dom.minidom import Node
from Bootstrap import conf as config
class Payloads:
    xmlpath = config.PAYLOAD_FILE
    Vulns = {}
    """
    Doc file Payload.xml lay thong tin ve cac lo hong
    """
    def __init__(self):
        doc = xml.dom.minidom.parse(self.xmlpath)
        print self.xmlpath
        for node in doc.getElementsByTagName("vulnerbility"):
            typeVuln = node.getAttribute("type")
            #print typeVuln
            decription = {}
            for node_decription in node.getElementsByTagName("decription"):
                decription["Vi"] = node_decription.getElementsByTagName("Vi")[0].childNodes[0].data
                decription["Eng"] = node_decription.getElementsByTagName("Eng")[0].childNodes[0].data
            #print decription
            payload = []
            for node_payload in node.getElementsByTagName("payload"):
                for sign in node_payload.getElementsByTagName("signature"):
                    payload.append(sign.getAttribute("value"))
                pass
            level = 0
            for level in node.getElementsByTagName("level"):
                level = level.getAttribute("value")
            name = ""
            for nameNode in node.getElementsByTagName("name"):
                name = nameNode.getAttribute("value")

            #print payload
            Vuln = {}
            Vuln["name"]        = name
            Vuln["Level"]       = level
            Vuln["decription"]  = decription
            Vuln["payload"]     = payload
            self.Vulns[typeVuln] = Vuln

def main():
    payload = Payloads()
    for v,w in payload.Vulns.iteritems():
        print v + "=====>"
        for v1,w2 in w.iteritems():
            print v1 + "--", w2
    pass

if __name__ == '__main__':
    main()
